# -*- coding: utf-8 -*-
import requests
import time

def getHTMLText(url):
    try:
        r = requests.get(url, timeout=30)
        r.raise_for_status() #如果状态码不是200，则引发HTTPError异常
        r.encoding = r.apparent_encoding
        return r.text
    except:
        return '产生异常'


if __name__ == '__main__':
    url = 'http://www.baidu.com'
    startTime = time.clock()
    
    for i in range(100):
        getHTMLText(url)
    endTime = time.clock()
    print('消耗了%d秒'%(endTime - startTime))
